package com.hdoit.apollo.logical.statistics.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.hdoit.apollo.logical.statistics.dao.IStockChangeStatisticsDao;
import com.hdoit.apollo.logical.statistics.model.StockChangeRecord;
import com.hdoit.apollo.logical.statistics.model.StockChangeStatistics;
import com.hdoit.apollo.logical.statistics.service.IStockChangeStatisticsService;
import com.hdoit.apollo.logical.viewmodel.statistics.StockChangeRecordSearch;
import com.hdoit.apollo.logical.viewmodel.statistics.StockChangeStatisticsSearch;
import com.tennetcn.data.dao.base.impl.SuperService;
import com.tennetcn.data.message.PagerModel;


@Component
public class StockChangeStatisticsServiceImpl extends SuperService<StockChangeStatistics> implements IStockChangeStatisticsService{
	@Autowired
	private IStockChangeStatisticsDao stockChangeStatisticsDao;
	
	@Override
	public StockChangeStatistics getStockChangeStatistics(StockChangeStatisticsSearch search) {
		
		return stockChangeStatisticsDao.getStockChangeStatistics(search);
	}

	@Override
	public List<StockChangeRecord> getStockChangeRecords(StockChangeRecordSearch search, PagerModel pagerModel) {
		List<StockChangeRecord> stockChangeRecords=new ArrayList<StockChangeRecord>();
		if(!StringUtils.isEmpty(search.getRecordType())) {
			switch(search.getRecordType())
	    	{
	    	case "inStock":
	    		List<StockChangeRecord> inStockChangeRecords=stockChangeStatisticsDao.getInStockChangeRecords(search,pagerModel);
				stockChangeRecords.addAll(inStockChangeRecords);
	    	  break;
	    	case "outStock":
	    		List<StockChangeRecord> outStockChangeRecords=stockChangeStatisticsDao.getOutStockChangeRecords(search,pagerModel);
	    		stockChangeRecords.addAll(outStockChangeRecords);
	    	  break;
		    case "outStockFahuo":
		    	List<StockChangeRecord> outStockFahuosChangeRecords=stockChangeStatisticsDao.getOutStockChangeOutStockFahuo(search,pagerModel);
		    	stockChangeRecords.addAll(outStockFahuosChangeRecords);
			  break;
		    case "outStockReturn":
		    	List<StockChangeRecord> outStockReturnRecords=stockChangeStatisticsDao.getOutStockReturnRecords(search,pagerModel);
		    	stockChangeRecords.addAll(outStockReturnRecords);
			  break;
		    case "adjustment":
		    	List<StockChangeRecord> adjustmentChangeRecords=stockChangeStatisticsDao.getAdjustmentChangeRecords(search,pagerModel);
		    	stockChangeRecords.addAll(adjustmentChangeRecords);
			  break;
		    case "inventory":
		    	List<StockChangeRecord> inventoryChangeRecords=stockChangeStatisticsDao.getInventoryChangeRecords(search,pagerModel);
		    	stockChangeRecords.addAll(inventoryChangeRecords);
			  break;
			}
		}else {
			/*//入库
			List<StockChangeRecord> inStockChangeRecords=stockChangeStatisticsDao.getInStockChangeRecords(search,pagerModel);
			//出库
			List<StockChangeRecord> outStockChangeRecords=stockChangeStatisticsDao.getOutStockChangeRecords(search,pagerModel);
			//发货
			List<StockChangeRecord> outStockFahuosChangeRecords=stockChangeStatisticsDao.getOutStockChangeOutStockFahuo(search,pagerModel);
			//盘点与
			List<StockChangeRecord> inventoryChangeRecords=stockChangeStatisticsDao.getInventoryChangeRecords(search,pagerModel);
			//调整
			List<StockChangeRecord> adjustmentChangeRecords=stockChangeStatisticsDao.getAdjustmentChangeRecords(search,pagerModel);
			//退货
			List<StockChangeRecord> outStockReturnRecords=stockChangeStatisticsDao.getOutStockReturnRecords(search,pagerModel);
			stockChangeRecords.addAll(inStockChangeRecords);
			stockChangeRecords.addAll(outStockChangeRecords);
			stockChangeRecords.addAll(outStockFahuosChangeRecords);
			stockChangeRecords.addAll(inventoryChangeRecords);
			stockChangeRecords.addAll(adjustmentChangeRecords);
			stockChangeRecords.addAll(outStockReturnRecords);*/
			stockChangeRecords=stockChangeStatisticsDao.getStockChangeRecordList(search,pagerModel);
		}

		return stockChangeRecords;
	}

	@Override
	public List<StockChangeRecord> getReturnRecord(StockChangeRecordSearch search, PagerModel pagerModel) {
		List<StockChangeRecord> stockChangeRecords=new ArrayList<StockChangeRecord>();
		List<StockChangeRecord> outStockChangeRecords=stockChangeStatisticsDao.getOutStockFahuoRecords(search,pagerModel);
		List<StockChangeRecord> outStockReturnRecords=stockChangeStatisticsDao.getOutStockReturnRecords(search,pagerModel);
		stockChangeRecords.addAll(outStockChangeRecords);
		stockChangeRecords.addAll(outStockReturnRecords);
		return stockChangeRecords;
	}

	@Override
	public List<StockChangeRecord> getStockChangeRecordList(StockChangeRecordSearch search, PagerModel pagerModel) {
		return stockChangeStatisticsDao.getStockChangeRecordList(search,pagerModel);
	}
	
}